"""
对于字典的操作，字典{key:value} 通过键值对的方式存储数据
创建字典
    dict1 = {}
    dict2 = dict()
    dict3 = {"xxx":xxx}
    == 判断两个字典是否相等，比较的应该是字典的内容

增 dict["xxx"] = xxxx
删 del dict["xx"]
删 del dict["xx"]  , dict.clear()
查
    dict["xxx"]
    dict.get("key" , 默认值) 如果查不到返回个默认值，如果查不到还没给默认值返回None
    dict.keys #
    dict.values
    dict.items
遍历

"""
#空字典；
dict0 = {}
dict0["name"] = "jurry"
print(dict0)
#空字典
dict1 = dict()
dict1["name"] = "jurry"
print(dict1)
print(dict1 == dict0) # True

dict11 = dict()
dict22 = dict()
print(dict22 == dict11) # True
print(dict11 == dict1) # False

dict2 = {"name": "Tom",
         "age": 12,
         "address": "上海"}
print(dict2.get("name"))

"""
增 dict["xxx"] = xxxx 
"""
dict3 = {}
dict3["name"] = "jurry"
dict3["age"] = 12
dict3["school"] = "shangying"
print(dict3)
"""
删 del dict["xx"]
"""
del dict3["school"]
print(dict3)
#dict3.clear()
#print(dict3)

"""
改 dict["xxx"] = xxxx 
"""
dict3['name'] = "lucy"
print(dict3)

"""
查：
dict["xxx"]
dict.get("key" , 默认值) 如果查不到返回个默认值，如果查不到还没给默认值返回None
dict.keys #
dict.values
dict.items
"""
dict4 = {"name": "Tom",
         "age": 12,
         "address": "上海"}
print(dict4["name"])
print(dict4.get("name"))
print(dict4.get("school"))
print(dict4.get("school" , "没有学校上"))
print(dict4.keys())
print(dict4.values())
print(dict4.items())

# 遍历所有的键
print("遍历所有的键")
for k in dict4.keys():
    print(k)

print("遍历所有的值")
for v in dict4.values():
    print(v)

print("遍历时通过键得到值")
for k in dict4.keys():
    print(dict4.get(k))
print("遍历items")
for i in dict4.items():
    print(i)

